import {Component} from 'react';
import {connect} from 'react-redux';
import {action} from "./model";
import './index.less';

class Demo extends Component {
    constructor(props) {
        super(props);//父组件中定义一个函数，包含一个props的参数，函数内利用super（props）传递给子组件，
        this.state = { // this.state中用于定义本页面中要用到的以及要传递给子组件的变量。
            name: ""
        };
    }
    componentWillMount () {
        console.log("new-componentWillMount");
    }
    componentDidMount () {
        this.props.getList();
        console.log("new-componentDidMount");
    }


  render() {
        console.log("render");
        console.log(this.props.demoInfo);
    return (
      <div>
          {(!this.props.demoInfo.name ||!this.props.demoInfo.name )&& <h1>Hello world!</h1>}
          {this.props.demoInfo.name && this.props.demoInfo.name && <h1>Hello, {this.props.demoInfo.name} !</h1>}
      </div>
    );
  }
}
const mapStateprops = (state) => {
    const {demoInfo} = state.demoReducer;
    console.log("mapStateprops");
    console.log(state.demoReducer);
    return {
        demoInfo
    };
};
export default connect (mapStateprops,action)(Demo);

